home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / shells / kiss-0.11 / kiss-0 / kiss / src / launch.c < prev    next >
C/C++ Source or Header  |  1995-03-23  |  1KB  |  48 lines

  1. #include "kiss.h"
  2.  
  3. void launch (Stringstack org, int infile, int outfile)
  4. {
  5.     register int
  6.     i;
  7.     Stringstack
  8.     s;
  9.     
  10.     /* signals to default */
  11.     signal (SIGINT, SIG_DFL);
  12.     signal (SIGQUIT, SIG_DFL);
  13.     signal (SIGTSTP, SIG_DFL);
  14.     signal (SIGTTIN, SIG_DFL);
  15.     signal (SIGTTOU, SIG_DFL);
  16.     signal (SIGCHLD, SIG_DFL);
  17.  
  18.     /* see if we're redirected */
  19.     if (infile != STDIN_FILENO)
  20.     {
  21.     dup2 (infile, STDIN_FILENO);
  22.     close (infile);
  23.     }
  24.     if (outfile != STDOUT_FILENO)
  25.     {
  26.     dup2 (outfile, STDOUT_FILENO);
  27.     close (outfile);
  28.     }
  29.     
  30.     /* re-expand wildcards and environment variables */
  31.     s = reexpand (org);
  32.  
  33.     /* launch internal command if that is the name */
  34.     /* note: this is a child process, we can alter `progname' */
  35.     progname = s.str [0];
  36.     if ( (i = isinternal (s.str [0])) != -1 )
  37.     exit (cmdtable [i].cmd (s));
  38.  
  39.     /* launch external program */
  40.     /* append last NULL for exec */
  41.     s.str = xrealloc (s.str, (s.nstr + 1) * sizeof (char *));
  42.     s.str [s.nstr] = NULL;
  43.  
  44.     execvp (s.str [0], s.str);
  45.     warning ("command not found", s.str [0]);
  46.     exit (1);
  47. }
  48.